import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import { getLanguage } from '@/i18n'
import { Get_LocationCity, Set_LocationCity } from '@/utils/auth'
import store from '@/store'


export interface IAppState {
	opened: boolean
	language: string
	locationCity: string
}

@Module({ dynamic: true, store, name: 'App' })
class App extends VuexModule implements IAppState {
	public opened = false
	public language = getLanguage()
	public locationCity = Get_LocationCity()

	@Mutation
	TOGGLE_SIDEBAR() {
		this.opened = !this.opened
	}

	@Mutation
	TOGGLE_LANGUAGE(language: string) {
		this.language = language
		localStorage.setItem('languageStatus', language);
	}

	@Mutation
	SET_LocationCity(City: any) {
		this.locationCity = City
		Set_LocationCity(City)
	}

	@Action
	public toggleSideBar() {
		this.TOGGLE_SIDEBAR()
	}

	@Action
	public toggleLanguage(language: string) {
		this.TOGGLE_LANGUAGE(language)
	}
}

export const AppModule = getModule(App)